﻿<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="database.DAO, golf.ProductService, golf.Account"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>요금제 구입</title>
</head>

<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<%
DAO dao = DAO.getInstance();
ProductService[] products = dao.getProductServiceList();
String accountID = (String)session.getAttribute("accountID");
Account account = dao.getAccount(accountID);

if( account.getPs_no() != 0 ){
	//사용하고 있는 요금제 출력.
	ProductService ps = dao.getProductService(account.getPs_no());
	
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
	java.util.Calendar cal = java.util.Calendar.getInstance();
	
	cal.setTime(account.getPs_buy_date());
	cal.add(java.util.Calendar.DATE, ps.getPeriod() );
	
	//Date date
	//Calendar cal;
	out.println( "회원님은 아래의 요금제를 사용하고 있습니다.");
%>
	<table cellspacing="0" width="80%" border="1" bordercolordark="white" bordercolorlight="black">
        <tr>
            <td width="100"><span style="font-size:9pt;">요금상품명</span></td>
            <td width="50"><span style="font-size:9pt;">가격</span></td>
            <td width="50"><span style="font-size:9pt;">구입날짜</span></td>
            <td width="50"><span style="font-size:9pt;">만료날짜</span></td>
            <td width="30"><span style="font-size:9pt;">상품등급명</span></td>
            <td width="30"><span style="font-size:9pt;">경험치 추가</span></td>
            <td width="30"><span style="font-size:9pt;">상금 추가</span></td>
            <td width="30"><span style="font-size:9pt;">코스그린피 추가</span></td>
        </tr>
        <tr>
        	<td width="100"><span style="font-size:9pt;"><%=ps.getName() %></span></td>
            <td width="50"><span style="font-size:9pt;"><%=ps.getPrice() %></span></td>
            <td width="50"><span style="font-size:9pt;"><%=account.getPs_buy_date().toString() %></span></td>
            <td width="50"><span style="font-size:9pt;"><%=sdf.format(cal.getTime()) %></span></td>
            <td width="30"><span style="font-size:9pt;"><%=ps.getGrade_name() %></span></td>
            <td width="30"><span style="font-size:9pt;"><%=ps.getGrade_exp() %></span></td>
            <td width="30"><span style="font-size:9pt;"><%=ps.getGrade_prize() %></span></td>
            <td width="30"><span style="font-size:9pt;"><%=ps.getGrade_course_green_fee() %></span></td>            
        </tr>
	</table>

<%}
else{%>
	<form name="form1" method="post" action="../post/postPurchase.jsp">
		<table cellspacing="0" width="80%" border="1" bordercolordark="white" bordercolorlight="black">
	        <tr>
	            <td width="100"><span style="font-size:9pt;">요금상품명</span></td>
	            <td width="50"><span style="font-size:9pt;">가격</span></td>
	            <td width="50"><span style="font-size:9pt;">지속기간</span></td>
	            <td width="30"><span style="font-size:9pt;">상품등급명</span></td>
	            <td width="30"><span style="font-size:9pt;">경험치 추가</span></td>
	            <td width="30"><span style="font-size:9pt;">상금 추가</span></td>
	            <td width="30"><span style="font-size:9pt;">코스그린피 추가</span></td>
	            <td width="30"><span style="font-size:9pt;">상품선택</span></td>
	        </tr>
	      <%
	      for(int i = 0; i < products.length; i++ ){
	      %>	
	        <tr>
	        	<td width="100"><span style="font-size:9pt;"><%=products[i].getName() %></span></td>
	            <td width="50"><span style="font-size:9pt;"><%=products[i].getPrice() %></span></td>
	            <td width="50"><span style="font-size:9pt;"><%=products[i].getPeriod() %></span></td>
	            <td width="30"><span style="font-size:9pt;"><%=products[i].getGrade_name() %></span></td>
	            <td width="30"><span style="font-size:9pt;"><%=products[i].getGrade_exp() %></span></td>
	            <td width="30"><span style="font-size:9pt;"><%=products[i].getGrade_prize() %></span></td>
	            <td width="30"><span style="font-size:9pt;"><%=products[i].getGrade_course_green_fee() %></span></td>
	            <td width="30"><span style="font-size:9pt;"><input type="radio" name="buyPsno" id="1" value="<%=products[i].getNo() %>"></span></td>
	            
	        </tr>
	      <%}%>
	    </table>
	    <p><input type="submit" name="okay" value="구매하기"><input type="reset" name="cancel" value="취소"></p>
	</form>
<%} %>
</body>

</html>